# Maintainer: Felix Yan <felixonmars@archlinux.org>

_hkgname=ral
pkgname=haskell-ral
pkgver=0.2.1
pkgrel=134
pkgdesc="Random access lists"
url="https://github.com/phadej/vec"
license=("GPL")
arch=('loong64' 'x86_64')
depends=('ghc-libs' 'haskell-quickcheck' 'haskell-adjunctions' 'haskell-bin' 'haskell-boring'
         'haskell-distributive' 'haskell-fin' 'haskell-hashable' 'haskell-indexed-traversable'
         'haskell-semigroupoids')
makedepends=('ghc' 'uusi')
source=("https://hackage.haskell.org/packages/archive/$_hkgname/$pkgver/$_hkgname-$pkgver.tar.gz")
sha512sums=('142edccb920b30ea7a98f45b326818e18b3f6e223d980c82f972f882e580aff8c1fbff5619ea43f8e410b193adce31c8bfbcb448be32b4e523646eddb775c717')

prepare() {
  cd $_hkgname-$pkgver
  gen-setup
  uusi -u fin $_hkgname.cabal
}

build() {
  cd $_hkgname-$pkgver

  runhaskell Setup configure -O --enable-shared --enable-executable-dynamic --disable-library-vanilla \
    --prefix=/usr --docdir=/usr/share/doc/$pkgname --datasubdir=$pkgname --enable-tests \
    --dynlibdir=/usr/lib --libsubdir=\$compiler/site-local/\$pkgid --ghc-option=-fllvm \
    --ghc-option=-optl-Wl\,-z\,relro\,-z\,now \
    --ghc-option='-pie'

  runhaskell Setup build $MAKEFLAGS
  runhaskell Setup register --gen-script
  runhaskell Setup unregister --gen-script
  sed -i -r -e "s|ghc-pkg.*update[^ ]* |&'--force' |" register.sh
  sed -i -r -e "s|ghc-pkg.*unregister[^ ]* |&'--force' |" unregister.sh
}

package() {
  cd $_hkgname-$pkgver

  install -D -m744 register.sh "$pkgdir"/usr/share/haskell/register/$pkgname.sh
  install -D -m744 unregister.sh "$pkgdir"/usr/share/haskell/unregister/$pkgname.sh
  runhaskell Setup copy --destdir="$pkgdir"
  rm -f "$pkgdir"/usr/share/doc/$pkgname/LICENSE
}
